package com.situ.day6;

public class Student {
    //private只能在类的内部访问
    private int id;
    private String name;
    private int age;

    //无参构造方法
    //如果不写任何的构造方法，java默认提供一个无参构造方法
    public Student() {

    }

    //有参构造方法
    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    //public 所有的地方都可以访问
    public void setId(int id) {
        //The value id assigned to 'id' is never used
        //就近原则
        //id = id;
        //this代表当前类的对象
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        //加控制条件
        if (age >= 0 && age <= 120) {
            this.age = age;
        }
    }

    public void study() {
        System.out.println(name + "正在学习");
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
